package com.jews.example.demo.domain.user.updater;

import com.jews.example.demo.domain.user.User;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Optional;

/**
 * 业务层(Service)修改请求对象
 * 命名规则：XxxUpdater
 *
 * @author JewsChen
 * @title: UserUpdater
 * @date 2022/11/29 23:29
 */
@Data
@NoArgsConstructor
public class UserUpdater {

    /**
     * 自增id
     */
    private Long id;

    /**
     * 手机号
     */
    private String phone;

    /**
     * 密码
     */
    private String password;

    /**
     * 用户名
     */
    private String username;

    /**
     * 部门ID
     */
    private Long departmentId;

    /**
     * 额外信息
     */
    private String extInfo;

    public void updateUser(User param) {
        Optional.ofNullable(this.getPhone()).ifPresent(param::setPhone);
        Optional.ofNullable(this.getPassword()).ifPresent(param::setPassword);
        Optional.ofNullable(this.getUsername()).ifPresent(param::setUsername);
        Optional.ofNullable(this.getDepartmentId()).ifPresent(param::setDepartmentId);
        Optional.ofNullable(this.getExtInfo()).ifPresent(param::setExtInfo);
    }
}
